import { defineStore } from "pinia";

const useHomeStore = defineStore("home", {
  state: () => ({
    count: 1,
    friend: [
      { name: "2", id: 1 },
      { name: "3", id: 2 },
      { name: "4", id: 3 },
    ],
  }),
  getters: {
    // 1.基本使用
    doubleCount(state) {
      return state.count * 2;
    },
    //2.一个getter引入另外一个getter
    doubleCountAddOne() {
      return this.doubleCount + 1;
    },
    // 3.getter支持返回一个函数
    getFriendById(state) {
      return function (id) {
        console.log(id, state.friend);
        return state.friend.find((item) => item.id == id);
      };
    },
    // 4.getter中用到别的store中的数据
    showMessage(state) {
      // (1)首先使用imput导入某个文件
      // const userStore = useStore()
      // userStore.name
    },
  },
  actions: {
    accumulate() {
      this.count++;
    },
  },
});
export default useHomeStore;
